<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册页面</title>
		<style>
			*{margin: 0;padding: 0;}
			body{
				width: 100%;
				height: 100%;
				background: url(body.jpg);
			    background-size: cover;	
			}
			.warp{
				width: 300px;
				height: 300px;
				margin: 50px auto;
		        
			}
			h2{
				font-weight: normal;
				padding-left: 10px;
				padding-top: 10px;
				font-family: "楷体";
			}
			input{
				margin-left: 10px;
				margin-top: 20px;
			}
			button{
				display:block;
				margin-top: 20px;
				margin-left: 10px;
				
			}
		</style>
	</head>
	<body>
		<div class="warp">
			 <h2>页面注册</h2>
			<input type="text" class="user"><span>用户名</span>
			<input type="text" class="password"><span>密码</span>
			<input type="text" class="repassword"><span>确认密码</span>
			<button class="register">注册</button>
			学生<input type="radio" name="type" class="student" checked>
			老师<input type="radio" name="type" class="teach">
		</div>
		<script src="jquery.min.js"></script>
		<script type="text/javascript" src="comment.js"></script>
		<script>
			$(".register").click(function(){
				
				let user = $(".user").val()
				let password = $(".password").val()
				let repassword = $(".repassword").val()
				if(repassword !== password){
					alert("密码不一致")
					return
				}
				else{
					$.ajax({
						url:`${address}/register`,
						data:{
							username:user,
							password:password,
							usertype:$(".student")[0].checked ? 0 : 1
						},
						success(data){
						if(data === "success"){
							location.href = `${address}/login.html`
						}	
						else{
							alert("注册失败")
						}
							
						}
					})
				}
			})
		</script>	
		
	
	</body>
</html>
